Skip to content

Conversation

@jjonescz
Copy link
Member

@jjonescz jjonescz commented Oct 2, 2025

Closes #49286.

@jjonescz jjonescz added the Area-run-file Items related to the "dotnet run <file>" effort label Oct 2, 2025
@jjonescz jjonescz force-pushed the sprint-project-vars branch from 9ad9ae2 to bc17aea Compare October 2, 2025 08:52
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds support for MSBuild variable expansion inside #:project directives and updates tests and documentation accordingly.

  • Introduces directive evaluation pass (EvaluateDirectives) to expand MSBuild variables and resolve project paths.
  • Extends CSharpDirective.Project to preserve original and unresolved names for later path adjustments during project conversion.
  • Adds tests covering variable usage and updates documentation about variable handling limitations.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
RunTelemetryTests.cs Adapts tests to new CSharpDirective.Project constructor.
RunFileTests.cs Adds tests for variable-based project references and malformed variable syntax.
DotnetProjectConvertTests.cs Adds test cases for variable-containing paths; updates expectations for cross-platform separators.
VirtualProjectBuildingCommand.cs Adds directive evaluation, caching of source file, and enhanced project directive handling.
ProjectConvertCommand.cs Integrates directive evaluation and updates path rewrite logic to preserve variable intent.
dotnet-run-file.md Documents variable support and caveats for #:project directives.

Co-authored-by: Copilot <[email protected]>
@jjonescz jjonescz marked this pull request as ready for review October 2, 2025 14:49
@jjonescz jjonescz requested a review from a team October 2, 2025 14:49
@RikkiGibson
Copy link
Member

The linked issue has milestone 10.0.2xx, was this PR meant to target release/10.0.2xx branch?

@jjonescz jjonescz changed the base branch from release/10.0.1xx to release/10.0.2xx October 2, 2025 18:36
@jjonescz
Copy link
Member Author

jjonescz commented Oct 2, 2025

Definitely, I was worried there might be changes missing in the 2xx branch, but looks like it's fairly up to date wrt file-based app PRs, so I can retarget now.

@jjonescz

This comment was marked as outdated.

@jjonescz jjonescz mentioned this pull request Oct 3, 2025
@jjonescz jjonescz added this to the 10.0.2xx milestone Oct 3, 2025
@dotnet dotnet deleted a comment from azure-pipelines bot Oct 3, 2025
@jjonescz
Copy link
Member Author

jjonescz commented Oct 8, 2025

@RikkiGibson @333fred @MiYanni for reviews, thanks

Comment on lines 1635 to 1636
? (project is null ? p : p.WithName(project.ExpandString(p.Name)))
.ResolveProjectPath(sourceFile, diagnostics)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: The original formatting here makes what ResolveProjectPath was being invoked on hard to see. Consider something more like this.

Suggested change
? (project is null ? p : p.WithName(project.ExpandString(p.Name)))
.ResolveProjectPath(sourceFile, diagnostics)
? (project is null
? p
: p.WithName(project.ExpandString(p.Name)))
.ResolveProjectPath(sourceFile, diagnostics)


public Project WithName(string name, bool preserveUnresolvedName = false)
{
return name == Name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels like we would also want to create a new instance if !preserveUnresolvedName && UnresolvedName != name. If we don't expect this to occur, it would probably be good to add an assertion to that effect.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, forgot to update this when adding the parameter.


// If the original path is to a directory, just append the resolved file name
// but preserve the variables from the original, e.g., `../$(..)/Directory/Project.csproj`.
if (Directory.Exists(project.UnresolvedName))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I am understanding right, project.UnresolvedName could be relative, creating a dependency on the process current directory. I think we should avoid that, e.g. by explicitly resolving relative to some known absolute path, like the Path of the containing SourceFile, before doing this check.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks, I will add a test for this too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-run-file Items related to the "dotnet run <file>" effort

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants